package server

import (
	"fmt"
	"math/rand"
	"server/base"
	"server/common/models/message"
	"server/common/utils"
	"server/pkg/cron/constant"
	"server/pkg/log"
	"server/pkg/nsq"
	"time"
)

type TestGroupMessage struct {
	constant.CornRegisterServiceParamBase
}

func (t *TestGroupMessage) GetCorn() string {
	return "*/1 * * * *"
}

func (t *TestGroupMessage) Run() {
	uid := rand.Intn(int(base.App.Config.App.PoolMatch.Max * 2))

	msg := message.GroupMessage{
		From:       utils.If(uid != 0, int64(uid), int64(1)).(int64),
		GroupId:    1,
		Type:       "text",
		Content:    fmt.Sprintf("test_%d", rand.Intn(100)),
		Status:     "unread",
		CreateTime: time.Now().Unix(),
		UpdateTime: time.Now().Unix(),
	}

	err := base.NsqClient.PushMessageToNsq(nsq.NsqMessage{
		Topic:   nsq.TOPIC_GROUP_MESSAGE,
		Message: msg.ToByte(),
	})

	if err != nil {
		log.Error("cron", err, "cron test group message error")
	}
}
